<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="css/Tree.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<script type="text/javascript" src="${ctx }/datepicker/WdatePicker.js"></script>
<script type="text/javascript"
	src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->
<s:if test="#request.classroom != null && #request.classroom.id > 0">
	<h1 class="page-title">培训室管理 - 修改</h1>
</s:if>
<s:else>
	<h1 class="page-title">培训室管理 - 添加</h1>
</s:else>
<div class="container_12 clearfix leading">
	<div class="side grid_12 leading">
		<form class="form has-validation" id="post_form" name="post_form">
			<s:if test="#request.classroom != null && #request.classroom.id > 0">
				<input type="hidden" name="classroom.id" value="${classroom.id}" />
			</s:if>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="title" class="form-label">名称 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="title" name="classroom.title"
						required="required" placeholder="请输入名称" value="${classroom.title}" />
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="level_org_sel" class="form-label">所属部门 <em>*</em></label>
				<div class="form-input">
					<select size="1" name="classroom.organization.id"
						id="level_org_sel">
						<!-- option selected="" value="3">├ 业务部</option>
						<option value="93">&#12288;&#12288;├ 业务一课</option>
						<option value="94">&#12288;&#12288;├ 业务二课</option>
						<option value="96">&#12288;&#12288;├ 业务三课</option>
						<option value="97">&#12288;&#12288;├ 业务四课</option>
						<option value="99">&#12288;&#12288;├ 业务五课</option>
						<option value="3">├ 人事部</option>
						<option value="3">├ 行政部</option>
						<option value="3">├ 财务部</option> -->
					</select>
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">生效日期 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="effective_date" name="effective_date"
						required="required" placeholder="请输入日期" onfocus="WdatePicker({maxDate: '#F{$dp.$D(\'expire_date\')}'})"
						value='<s:date name="#request.classroom.effectiveDate" format="yyyy-MM-dd"/>' />
				</div>
			</div>
			<div class="clear"></div>
			<div class="clearfix">
				<label for="form-email" class="form-label">到期日期 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="expire_date" name="expire_date"
						required="required" placeholder="请输入到期日期" onfocus="WdatePicker({minDate: '#F{$dp.$D(\'effective_date\')}'})"
						value='<s:date name="#request.classroom.expireDate" format="yyyy-MM-dd"/>' />
				</div>
			</div>
			<div class="clearfix">
				<label for="form-name" class="form-label">近期课程 <em>*</em></label>
				<div class="form-input">
					<input type="text" id="recent_course" name="classroom.recentCourse"
						required="required" placeholder="请输入主要课程"
						value="${classroom.recentCourse}" />
				</div>
			</div>
			<div class="form-action clearfix">
				<button class="button" type="button" onclick="checkForm()">
					<s:if test="#request.classroom.id > 0">修改</s:if>
					<s:else>添加</s:else>
				</button>
				<button class="button" type="reset">重置</button>
				<a class="button" href="javascript:void(0)"
					onclick="javascript:history.back()"><span
					style="background: url(${ctx}/images/img/arrow_undo.png)"
					class="icon">&nbsp;</span>返回</a>

			</div>

		</form>
	</div>
</div>

<div class="clear"></div>

<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$
								.ajax({
									type : "post",
									url : "/ajax/organization-top.xhtml?parentId=${organizationId}",
									dataType : "json",
									success : function(orginizations) {
										var tempStr = "<option value='-1'>├请选择</option>"
										var selcontent = "";
										if (orginizations != null && orginizations.length > 0) {
											for ( var i = 0; i < orginizations.length; i++) {
												if(orginizations[i].id == ${classroom.organization.id}){
													tempStr += "<option value='"+orginizations[i].id+"' selected=\"selected\">"
															+ orginizations[i].fullName
															+ "</option>";
													selcontent = orginizations[i].fullName;
												}else{
													tempStr += "<option value='"+orginizations[i].id+"'>"
															+ orginizations[i].fullName
															+ "</option>";
												}
											}
											$("#level_org_sel").prev("span").html(selcontent == "" ? "请选择" : selcontent);
											
										}
										$("#level_org_sel").html(tempStr);
									}
								});
					});

	function checkForm() {
		if ($("#title").val() == null || $("#title").val() == "") {
			alert("请输入名称");
			return;
		}

		if ($("#effective_date").val() == null
				|| $("#effective_date").val() == "") {
			alert("请输入生效日期");
			return;
		}

		if ($("#expire_date").val() == null || $("#expire_date").val() == "") {
			alert("请输入到期日期");
			return;
		}

		if ($("#recent_course").val() == null || $("#recent_course").val() == "") {
			alert("请输入主要课程");
			return;
		}

		var url = "${ctx}/train/post_classroom.xhtml";
		$
				.ajax(
						url,
						{
							type : "POST",
							data : $("#post_form").serialize(),
							dataType : "html",
							cache : false,
							success : function(a) {
								alert("提交成功");
								window.location.href = "${ctx}/index.xhtml#train/classroom_main.xhtml?organizationId=${classroom.organization.id}";
							},
							error : function(XMLHttpRequest, textStatus,
									errorThrown) {
								alert('提交申请发生异常');
							},
							complete : function() {
							}
						});

	}

	

	

	
</script>